// miniprogram/pages/mine/qrcode/qrcode.js
import drawQrcode from '../../../libs/weapp.qrcode.esm'
var QRCode = require('../../../libs/weapp-qrcode.js')

Page({

  data: {
    text:'id=1234567890',
    width:200
  },
  onLoad: function (options) {
    this.drawCanvas();
    this.drawCanvasOld()
  },
  onShareAppMessage: function () {

  },
  drawCanvas () {
    drawQrcode({
      width: this.data.width,
      height: this.data.width,
      canvasId: 'myQrcode',
      text: this.data.text,
      callback(e) {
        console.log('e: ', e)
      }
    })
  },
  drawCanvasOld(){
    var qrcode = new QRCode('canvasId', {
      text: this.data.text,
      width: this.data.width,
      height: this.data.width,
      colorDark: "#000000",
      colorLight: "#ffffff",
      correctLevel: QRCode.CorrectLevel.H,
      callback: (res) => {
        // 生成二维码的临时文件
        console.log(res.path)
      }
    });
  }
})